using Framework;
using UnityEngine;
using Cinemachine;

namespace Game
{
    public class RoleWarriorEntity : BaseWarriorEntity
    {
        Camera m_MainCamera;
        Vector3 m_MoveDirection;
        CinemachineFreeLook m_ThirdPersonCamera;
        bool m_IsPause = false;

        public override void Init()
        {
            this.m_MainCamera = GameRoot.Instance.MainCamera;
            this.m_ThirdPersonCamera = (GameEntry.Scene.Scene as FightScene).ThirdPersonCamera;
            base.Init();
        }

        public void PauseFight()
        {
            this.m_ThirdPersonCamera.enabled = false;
            this.m_IsPause = true;
        }

        public void ResumeFight()
        {
            this.m_ThirdPersonCamera.enabled = true;
            this.m_IsPause = false;
        }

        public override void OnCharacterRefresh()
        {
            this.m_ThirdPersonCamera.Follow = this.Character.transform;
            this.m_ThirdPersonCamera.LookAt = this.Character.transform;
        }

        public override void Update(float elapseSeconds, float realElapseSeconds)
        {
            if (this.m_IsPause) return;
            float inputX = Input.GetAxis ("Horizontal");
            float inputZ = Input.GetAxis ("Vertical");
            if (inputX == 0 && inputZ == 0)
            {
                return;
            }
            Camera mainCamera = this.m_MainCamera;
            Vector3 forward = mainCamera.transform.forward;
            Vector3 right = mainCamera.transform.right;
            forward.y = 0f;
            right.y = 0f;
            forward.Normalize();
            right.Normalize();

            this.m_MoveDirection = forward * inputZ + right * inputX;

            this.Character.MoveByDirection(this.m_MoveDirection);
        }
    }
}